import Vue from 'vue'
import VueRouter from 'vue-router'
import JkyLayout from '@/views/JkyLayout'
import JkyHome from '@/views/JkyHome'
import JkyArticle from '@/views/JkyArticle'
import JkyQuestion from '@/views/JkyQuestion'
import JkyVideo from '@/views/JkyVideo'
import JkyUser from '@/views/JkyUser'
import JkyLogin from '@/views/JkyLogin'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: JkyLayout,
    children: [
      { path: '/home', component: JkyHome },
      { path: '/question', component: JkyQuestion },
      { path: '/video', component: JkyVideo },
      { path: '/user', component: JkyUser }
    ]
  },

  { path: '/article', component: JkyArticle },
  { path: '/login', component: JkyLogin }
]

const router = new VueRouter({
  routes
})

export default router
const witeList = ['/login']
router.beforeEach((to, form, next) => {
  if (localStorage.getItem('hm-jky-token')) {
    next()
  } else {
    if (witeList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
